package com.lin.netty.chat.handler;

import com.lin.netty.chat.message.LoginRequestMessage;
import com.lin.netty.chat.message.LoginResponseMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 登录请求消息入站处理器
 */
@Slf4j
public class LoginRequestMessageHandler extends SimpleChannelInboundHandler<LoginRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LoginRequestMessage msg) throws Exception {
        log.debug("收到登录请求：{},{}", msg.getUsername(), msg.getPassword());
        if ("123".equals(msg.getPassword()))
            ctx.writeAndFlush(new LoginResponseMessage(true, "登录成功"));
        else
            ctx.writeAndFlush(new LoginResponseMessage(false, "用户名或密码错误"));
    }
}
